package com.sumbo.config.pipeline;

import com.sumbo.config.processor.Processor;
import com.sumbo.config.writer.OutputContext;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * \* User: MeiZhongHao
 * \* Date: 2019-06-10
 * \* Time: 15:13
 * \* Description: 管道
 * \
 */
public class Pipeline {

    private String input;

    private String processor;

    private List<OutputContext> output;

    public Pipeline() {
    }

    public Pipeline(String input, String processor, List<OutputContext> output) {
        this.input = input;
        this.processor = processor;
        this.output = output;
    }

    public String getInput() {
        return input;
    }

    public void setInput(String input) {
        this.input = input;
    }

    public String getProcessor() {
        return processor;
    }

    public void setProcessor(String processor) {
        this.processor = processor;
    }

    public List<OutputContext> getOutput() {
        return output;
    }

    public void setOutput(List<OutputContext> output) {
        this.output = output;
    }

    public Processor getProcessorBean(){
        if (StringUtils.isEmpty(processor)) {
            return null;
        }
        try {
            return (Processor)Class.forName(processor).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
            return null;
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return null;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }
}